package com.baizhi.service.impl;

import com.baizhi.dao.StudentDao;
import com.baizhi.entity.Student;
import com.baizhi.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class StudentServiceImpl implements StudentService {
//    @Autowired
    @Resource
    private StudentDao studentDao;
    @Override
    public void insert(Student student) {
        studentDao.insert(student);
    }

    @Override
    public void delete(Integer id) {
        studentDao.delete(id);
    }

    @Override
    @Transactional(readOnly = true)
    public Student selectById(Integer id) {
        Student student = studentDao.selectById(id);
        return student;
    }

    @Override
    public void update(Student student) {
        studentDao.update(student);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Student> select(int page, int limit) {
        PageHelper.startPage(page, limit);
        List<Student> students = studentDao.selectAll();
        PageInfo<Student> pageInfo = new PageInfo<>(students);
        return pageInfo;
    }
}
